package com.shsxt.service;



import java.io.File;
import java.io.FileInputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.net.URLEncoder;
import java.security.KeyStore;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.UUID;

import javax.net.ssl.SSLContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayTradeAppPayModel;
import com.alipay.api.internal.util.AlipaySignature;
import com.alipay.api.request.AlipayTradeAppPayRequest;
import com.alipay.api.request.AlipayTradeRefundRequest;
import com.alipay.api.response.AlipayTradeAppPayResponse;
import com.alipay.api.response.AlipayTradeRefundResponse;
import com.shsxt.controller.Test;
import com.shsxt.dao.ControllDao;
import com.shsxt.dao.CouponDao;
import com.shsxt.dao.OrderDao;
import com.shsxt.dao.WodeDao;
import com.shsxt.dao.YuyueDao;
import com.shsxt.model.Address;
import com.shsxt.model.COrder;
import com.shsxt.model.Coupon;
import com.shsxt.model.DOrder;
import com.shsxt.model.JOrder;
import com.shsxt.model.KOrder;
import com.shsxt.model.Order;
import com.shsxt.model.ROrder;
import com.shsxt.model.SOrder;
import com.shsxt.model.ServicePersonal;
import com.shsxt.model.UserInfo;
import com.shsxt.model.YOrder;
import com.shsxt.model.YueMan;
import com.shsxt.util.RSA;
import com.shsxt.util.encoder.BASE64Encoder;
import com.shsxt.util.weixin.PayCommonUtil;
import com.shsxt.util.wx.GetWxOrderno;
import com.shsxt.util.wx.HttpClientConnectionManager;
import com.shsxt.util.wx.RequestHandler;

@Service
public class YuyueService {
	
	@Autowired
	private ControllDao controllDao;
	@Autowired
	private YuyueDao yuyueDao;
	@Autowired
	private  OrderDao orderDao;
	@Autowired
	private  OrderService orderService;
	@Autowired
	private WodeDao wodeDao;
	@Autowired
	private CouponDao couponDao;
	public  synchronized  Map<String, Object> rdanci(String uuid, String serviceTime1 ,String orderTime, String timeSlot,String suppilies,String phoneNumber) throws ParseException, UnsupportedEncodingException {
		Float serviceTime=Float.parseFloat(serviceTime1);
		Map<String,Object> param=new HashMap<String,Object>();
		Address ad=wodeDao.findAddressByUuid(uuid);
		param.put("orderTime", changeDay(orderTime));
		String orderNumber=getOrderNumber();
		param.put("orderNumber",orderNumber );
		//手机号（PhoneNumber）日常保洁订单编号（OrderNumber）
		param.put("phoneNumber", phoneNumber);
		param.put("realPhoneNumber", ad.getRealPhoneNumber());
		//是否支持抢单（SupportType）抢单状态（RobListType）是否还可以抢日常保洁预定时间（OrderTime）
		param.put("supportType", "true");
		param.put("robListType", "true");
		
		//当天时间段（TimeSlot）服务时长（ServiceTime）服务地址（Address）
		param.put("timeSlot", timeSlot);
		param.put("serviceTime",serviceTime1);
		param.put("address",ad.getAddress());
		param.put("detailAddress",ad.getDetailAddress());
		param.put("location",ad.getLocation());
		param.put("cleaningSupplies_Price",0f);
		param.put("price",75f);
		if(suppilies.equals("1")){
			param.put("cleaningSupplies_Price", serviceTime*5);
		}
		//服务人员（ServicePersonal）保洁剂价格（CleaningSupplies_Price）总价（Price）
		if(serviceTime!=2){
			param.put("price", 30f*serviceTime);
		}
		//实际价格（R_RealPrice）/会员可享价格服务人员收入价格（Service_Price）日常保洁订单状态（OrderState）
		/*String vip=wodeDao.findUserByPhone(phoneNumber).getMemberLevel();
		if(vip.equals("VIP1")||vip.equals("VIP2")){
			param.put("price",(Float)param.get("price")*(0.75f));
		}else if(vip.equals("VIP3")||vip.equals("VIP4")){
			param.put("price",(Float)param.get("price")*(0.7f));
		}else if(vip.equals("VIP5")||vip.equals("VIP6")){
			param.put("price",(Float)param.get("price")*(0.65f));
		}*/
		param.put("price",(Float)param.get("price")+(Float)param.get("cleaningSupplies_Price"));
		param.put("service_Price",(Float)param.get("price")*0.05);
		yuyueDao.rdanci(param);
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("orderNumber",orderNumber);
		return map;
		}
	public Map<String, Object> rDanciZhifu(String orderNumber) {
		ROrder r=orderDao.findROrder(orderNumber);
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("0", r.getAddress()+r.getDetailAddress());
		return map;
	}
	//添加优惠券接口
	public Map<String, Object> addCoupon(String redeemCode,String orderNumber,String type) {
		Map<String,Object> map=new HashMap<String,Object>();
		Coupon cp=yuyueDao.findCouponByRedeemCode(redeemCode);
		Float price=0f;
		if(type.equals("日常保洁")){
			ROrder r= orderDao.findROrder(orderNumber);
			price=r.getPrice();
		}else if(type.equals("沙发护理")){
			SOrder r= orderDao.findSOrder(orderNumber);
			price=r.getPrice();
		}else if(type.equals("开荒保洁")){
			KOrder r= orderDao.findKOrder(orderNumber);
			price=r.getPrice();
		}else if(type.equals("家电清洗")){
			JOrder r= orderDao.findJOrder(orderNumber);
			price=r.getPrice();
		}else if(type.equals("地板护理")){
			DOrder r= orderDao.findDOrder(orderNumber);
			price=r.getPrice();
		}else if(type.equals("擦玻璃")){
			COrder r= orderDao.findCOrder(orderNumber);
			price=r.getPrice();
		}
		if(redeemCode.equals("")||cp==null){
			map.put("0", "失败");
			return map;
		}
		if(cp.getState().equals("满100使用")){
			if(price>100f){
				map.put("0", "失败");
				return map;
			}
		}else if(cp.getState().equals("满200使用")){
			if(price>200f){
				map.put("0", "失败");
				return map;
			}
		}
		map.put("0", "成功");
		
		return map;
	}
	public Map<String, Object> toPay( String orderNumber, String type) throws ParseException {
		Map<String,Object> map=new HashMap<String,Object>();
		
		Map<String,Object> result=new HashMap<String,Object>();
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd EEEE");
		 SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
		if(type.equals("日常保洁")){
			ROrder r= orderDao.findROrder(orderNumber);
			result.put("address", r.getAddress()+r.getDetailAddress());
			result.put("realPhoneNumber",r.getRealPhoneNumber());
			result.put("daojishi", orderService.findDaojishi(orderNumber, type));
			result.put("realPrice", r.getRealPrice()+"元");
			if(r.getOrderTime()!=null){
					result.put("orderTime", format.format(ft.parse(r.getOrderTime()))+r.getTimeSlot());
		
			
			}else {
				SimpleDateFormat to=new SimpleDateFormat("yyyy-MM-dd EEEE");
				SimpleDateFormat from=new SimpleDateFormat("yyyy年MM月dd日");
				String[] days=r.getCircle().split(";");
				String c=to.format(from.parse(days[0]))+"开始服务";
				result.put("orderTime", c);
			}
			result.put("vip",wodeDao.findUserByPhone(r.getPhoneNumber()).getMemberLevel().substring(3) );
			
		}else if(type.equals("沙发护理")){
			SOrder r= orderDao.findSOrder(orderNumber);
			result.put("address", r.getAddress()+r.getDetailAddress());
			result.put("realPhoneNumber",r.getRealPhoneNumber());
			result.put("orderTime", format.format(ft.parse(r.getOrderTime()))+r.getTimeSlot());
			result.put("realPrice", r.getRealPrice()+"元");
			result.put("daojishi", orderService.findDaojishi(orderNumber, type));
			result.put("vip",wodeDao.findUserByPhone(r.getPhoneNumber()).getMemberLevel().substring(3) );

		}else if(type.equals("开荒保洁")){
			KOrder r= orderDao.findKOrder(orderNumber);
			result.put("address", r.getAddress()+r.getDetailAddress());
			result.put("realPhoneNumber",r.getRealPhoneNumber());
			result.put("orderTime", format.format(ft.parse(r.getOrderTime()))+r.getTimeSlot());
			result.put("realPrice", r.getRealPrice()+"元");
			result.put("daojishi", orderService.findDaojishi(orderNumber, type));
			result.put("vip",wodeDao.findUserByPhone(r.getPhoneNumber()).getMemberLevel().substring(3) );


		}else if(type.equals("家电清洗")){
			JOrder r= orderDao.findJOrder(orderNumber);
			result.put("address", r.getAddress()+r.getDetailAddress());
			result.put("realPhoneNumber",r.getRealPhoneNumber());
			result.put("orderTime", format.format(ft.parse(r.getOrderTime()))+r.getTimeSlot());
			result.put("realPrice", r.getRealPrice()+"元");
			result.put("daojishi", orderService.findDaojishi(orderNumber, type));
			result.put("vip",wodeDao.findUserByPhone(r.getPhoneNumber()).getMemberLevel().substring(3) );


		}else if(type.equals("地板护理")){
			DOrder r= orderDao.findDOrder(orderNumber);
			result.put("address", r.getAddress()+r.getDetailAddress());
			result.put("realPhoneNumber",r.getRealPhoneNumber());
			result.put("orderTime", format.format(ft.parse(r.getOrderTime()))+r.getTimeSlot());
			result.put("realPrice", r.getRealPrice()+"元");
			result.put("daojishi", orderService.findDaojishi(orderNumber, type));
			result.put("vip",wodeDao.findUserByPhone(r.getPhoneNumber()).getMemberLevel().substring(3) );


		}else if(type.equals("擦玻璃")){
			COrder r= orderDao.findCOrder(orderNumber);
			result.put("address", r.getAddress()+r.getDetailAddress());
			result.put("realPhoneNumber",r.getRealPhoneNumber());
			result.put("orderTime", format.format(ft.parse(r.getOrderTime()))+r.getTimeSlot());
			result.put("realPrice", r.getRealPrice()+"元");
			result.put("daojishi", orderService.findDaojishi(orderNumber, type));
			result.put("vip",wodeDao.findUserByPhone(r.getPhoneNumber()).getMemberLevel().substring(3) );

		}
		
		map.put("A", result);
		return map;
	}	
	//获取单次预约约满表
	public Map<String, Object> getYueMan(String type,String day,String serviceTime,String uuid) throws ParseException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, UnsupportedEncodingException {
		if(serviceTime==null){
			serviceTime="4";
		}
		List<String> list=new ArrayList<String>();
		List<String> list2=new ArrayList<String>();

		int count=getAuntCount(type,uuid);
		//int类型的服务时长
		int timeLong=Integer.valueOf(serviceTime);
		//根据服务时长 得到i<end
		int end=19-timeLong;
		String oneYueman="";//true代表可约
			for(int i=8;i<end;i++){
				for(int y=0;y<=timeLong;y++){
					if(getOneYueMan(day, i+y)>=count){
						 oneYueman="约满";
					}
				}
				list.add(oneYueman);
				oneYueman="";
			}
			Map<String,Object> map=new HashMap<String,Object>();

			if(new SimpleDateFormat("yyyy年M月dd日").format(new Date()).equals(day)||new SimpleDateFormat("yyyy年MM月dd日").format(new Date()).equals(day)){
				System.err.println("111111111");

				int a=Integer.valueOf(new SimpleDateFormat("HH").format(new Date()))-7;
				if(a>=11-timeLong){
					a=11-timeLong;
				}
				for(int i=1;i<=a;i++){
					list2.add("约满");
				}
				for(int i=a+8;i<19-timeLong;i++){
					list2.add(list.get(i-8));
				}
				
				map.put("0", list2);
				return map;
					
				
			}
			
		
		/* Field[] field = ym.getClass().getDeclaredFields();  
		 for(int j=0 ; j<field.length ; j++){     //遍历所有属性
             String name = field[j].getName();    //获取属性的名字
             name = name.substring(0,1).toUpperCase()+name.substring(1); //将属性的首字符大写，方便构造get，set方法
                 Method m = ym.getClass().getMethod("get"+name);
                 String value = (String) m.invoke(ym);    //调用getter方法获取属性值
                 list.add(value);
                 }*/
		
		map.put("0", list);
		return map;
	}
	//进入预约 ,自动给默认地址
	public Map<String, Object> giveAddress(String phoneNumber) {
		 Address ad=yuyueDao.findAddressByPhone(phoneNumber);
		 Map<String,Object> map=new HashMap<String,Object>();
		 map.put("address", ad);
		return map;
	}
	public Map<String, Object> usableCoupon(String phoneNumber, String orderNumber, String type) {
		Map<String,Object> map=new HashMap<String,Object>();
		Map<String,Object> param=new HashMap<String,Object>();
		param.put("phoneNumber", phoneNumber);
		param.put("type", type);
		List<Coupon> list=new ArrayList<Coupon>();
		List<Coupon> realList=new ArrayList<Coupon>();
		//根据手机号和类型查找可用的优惠券
		list=yuyueDao.findCouponByPhoneType(param);
		Float price=0f;
		if(type.equals("日常保洁")){
			ROrder r= orderDao.findROrder(orderNumber);
			price=r.getPrice();
		}else if(type.equals("沙发护理")){
			SOrder r= orderDao.findSOrder(orderNumber);
			price=r.getPrice();
		}else if(type.equals("开荒保洁")){
			KOrder r= orderDao.findKOrder(orderNumber);
			price=r.getPrice();
		}else if(type.equals("家电清洗")){
			JOrder r= orderDao.findJOrder(orderNumber);
			price=r.getPrice();
		}else if(type.equals("地板护理")){
			DOrder r= orderDao.findDOrder(orderNumber);
			price=r.getPrice();
		}else if(type.equals("擦玻璃")){
			COrder r= orderDao.findCOrder(orderNumber);
			price=r.getPrice();
		}
		for(Coupon cp:list){
			if(cp.getState().equals("0")||(cp.getState().equals("200")&&price>200f)||(cp.getState().equals("100")&&price>100f)){
				realList.add(cp);
			}
		}
	 map.put("coupon", realList);

		return map;
	}
	public Map<String, Object> chooseCoupon(String redeemCode, String orderNumber, String type) {
		Map<String,Object> map=new HashMap<String,Object>();
		Map<String,Object> param=new HashMap<String,Object>();
		param.put("redeemCode", redeemCode);
		param.put("orderNumber", orderNumber);
		

		Coupon cp=yuyueDao.findCouponByRedeemCode(redeemCode);
		if(type.equals("日常保洁")){
			ROrder r= orderDao.findROrder(orderNumber);
			//判断订单是否已选优惠券并替换优惠券
			if(r.getRedeemCode()!=null){
				//还原该订单的realPrice 并把优惠券清空
				yuyueDao.resetRRedeemCode(orderNumber);
			}
			//给订单添加优惠券 修改真实价格
			param.put("realPrice", r.getPrice()-Float.parseFloat(cp.getDiscountAmount()));
			yuyueDao.setRRedeemCode(param);
		}else if(type.equals("沙发护理")){
			SOrder r= orderDao.findSOrder(orderNumber);
			param.put("realPrice", r.getPrice()-Float.parseFloat(cp.getDiscountAmount()));
			yuyueDao.setSRedeemCode(param);
		}else if(type.equals("开荒保洁")){
			KOrder r= orderDao.findKOrder(orderNumber);
			param.put("realPrice", r.getPrice()-Float.parseFloat(cp.getDiscountAmount()));
			yuyueDao.setKRedeemCode(param);
		}else if(type.equals("家电清洗")){
			JOrder r= orderDao.findJOrder(orderNumber);
			param.put("realPrice", r.getPrice()-Float.parseFloat(cp.getDiscountAmount()));
			yuyueDao.setJRedeemCode(param);
		}else if(type.equals("地板护理")){
			DOrder r= orderDao.findDOrder(orderNumber);
			param.put("realPrice", r.getPrice()-Float.parseFloat(cp.getDiscountAmount()));
			yuyueDao.setDRedeemCode(param);
		}else if(type.equals("擦玻璃")){
			COrder r= orderDao.findCOrder(orderNumber);
			param.put("realPrice", r.getPrice()-Float.parseFloat(cp.getDiscountAmount()));
			yuyueDao.setCRedeemCode(param);
		}
		map.put("0", "成功");
		return map;
	}	
	 static String changeDay(String day) throws ParseException{
		   SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日");
		   Date date =  format.parse(day);
		    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
		    return (df.format(date));
	   }
	public Map<String, Object> resetCoupon(String orderNumber, String type) {
		Map<String,Object> map=new HashMap<String,Object>();
		
		if(type.equals("日常保洁")){
			ROrder r= orderDao.findROrder(orderNumber);
			//判断订单是否已选优惠券并替换优惠券
			//还原该订单的realPrice 并把优惠券清空
			if(r.getRedeemCode()!=null){
				yuyueDao.resetRRedeemCode(orderNumber);
			}
		}else if(type.equals("沙发护理")){
			SOrder r= orderDao.findSOrder(orderNumber);
			if(r.getRedeemCode()!=null){
				yuyueDao.resetRRedeemCode(orderNumber);
			}
		}else if(type.equals("开荒保洁")){
			KOrder r= orderDao.findKOrder(orderNumber);
			if(r.getRedeemCode()!=null){
				yuyueDao.resetRRedeemCode(orderNumber);
			}
		}else if(type.equals("家电清洗")){
			JOrder r= orderDao.findJOrder(orderNumber);
			if(r.getRedeemCode()!=null){
				yuyueDao.resetRRedeemCode(orderNumber);
			}
		}else if(type.equals("地板护理")){
			DOrder r= orderDao.findDOrder(orderNumber);
			if(r.getRedeemCode()!=null){
				yuyueDao.resetRRedeemCode(orderNumber);
			}
		}else if(type.equals("擦玻璃")){
			COrder r= orderDao.findCOrder(orderNumber);
			if(r.getRedeemCode()!=null){
				yuyueDao.resetRRedeemCode(orderNumber);
			}
		}
		map.put("0", "成功");
		return map;
	}
	public  synchronized  Map<String, Object> ydanci(String uuid,String phoneNumber,String linkMan,String sex,String realPhoneNumber,String duedate) throws ParseException {
		Map<String,Object> map=new HashMap<String,Object>();
		Map<String,Object> param=new HashMap<String,Object>();
		Address ad=wodeDao.findAddressByUuid(uuid);
		Date date=new Date();
		 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		param.put("phoneNumber", phoneNumber);
		param.put("linkMan", linkMan);
		param.put("sex", sex);
		param.put("address",ad.getAddress());
		param.put("detailAddress", ad.getDetailAddress());
		param.put("realPhoneNumber", ad.getRealPhoneNumber());
		param.put("orderNumber",  getOrderNumber());
		param.put("orderTime", format.format(date));
		param.put("duedate",  duedate);
		yuyueDao.createYDanci(param);
		map.put("0",phoneId(linkMan,ad.getRealPhoneNumber()));
		return map;
	}
		
	private static String phoneId(String linkMan,String phoneNumber){
    	String phone=linkMan+"("+phoneNumber+")成功预约月嫂服务";
    	return phone;
    	}
	public  synchronized  Map<String, Object> bdanci(String phoneNumber, String uuid, String realPhoneNumber, String demand) throws ParseException {
		Map<String,Object> map=new HashMap<String,Object>();
		Map<String,Object> param=new HashMap<String,Object>();	
		Address ad=wodeDao.findAddressByUuid(uuid);
		param.put("phoneNumber", phoneNumber);
		param.put("address", ad.getAddress()+ad.getDetailAddress());
		param.put("realPhoneNumber", ad.getRealPhoneNumber());
		param.put("demand", demand);
		Date date=new Date();
		SimpleDateFormat xxx = new SimpleDateFormat("yyyyMMddHHmmss");
		SimpleDateFormat aaa = new SimpleDateFormat("yyyy-MM-dd");
		param.put("orderNumber",  getOrderNumber());
		param.put("orderTime",  aaa.format(date));
		yuyueDao.createBDanci(param);
		map.put("0","成功");
		return map;
	}
	public  synchronized  Map<String, Object> jDanci(String type,String uuid,String j_type, String typeDetail, String orderTime, String timeSlot,
			String phoneNumber) throws ParseException, UnsupportedEncodingException {
		Address ad=wodeDao.findAddressByUuid(uuid);
		Map<String,Object> param=new HashMap<String,Object>();
		Map<String,Object> map=new HashMap<String,Object>();
		param.put("phoneNumber", phoneNumber);
		param.put("address", ad.getAddress());
		param.put("detailAddress", ad.getDetailAddress());
		param.put("location", ad.getLocation());
		param.put("realPhoneNumber", ad.getRealPhoneNumber());
		param.put("j_type", j_type);
		param.put("typeDetail", typeDetail);
		if(type.equals("沙发护理")){
			param.put("typeDetail", typeDetail+"(座)");
		}else if(type.equals("地板护理")||type.equals("擦玻璃")){
			param.put("typeDetail", typeDetail+"(平方米)");
		}
		UserInfo user=wodeDao.findUserByPhone(phoneNumber);
		user.getMemberLevel();
		if(type.equals("沙发护理")){
			param.put("price", Float.valueOf(typeDetail)*100f);
		}else if(type.equals("开荒保洁")){
			if(typeDetail.equals("一居室(有家具)")||typeDetail.equals("一居室")||typeDetail.equals("一居室(无家具)")){
				param.put("price", 500f);
			}else if(typeDetail.equals("二居室1卫(有家具)")||typeDetail.equals("二居室1卫")||typeDetail.equals("二居室1卫(无家具)")){
				param.put("price", 750f);
			}else if(typeDetail.equals("二居室2卫(有家具)")||typeDetail.equals("二居室2卫")||typeDetail.equals("二居室2卫(无家具)")){
				param.put("price", 950f);
			}else if(typeDetail.equals("三居室1卫(有家具)")||typeDetail.equals("三居室1卫")||typeDetail.equals("三居室1卫(无家具)")){
				param.put("price", 1100f);
			}else if(typeDetail.equals("三居室2卫(有家具)")||typeDetail.equals("三居室2卫")||typeDetail.equals("三居室2卫(无家具)")){
				param.put("price", 1425f);
			}else{
				param.put("typeDetail", "四居室"+typeDetail.substring(0, 3)+"(平方米)"+typeDetail.substring(3, typeDetail.length()));
				param.put("price",Float.valueOf(typeDetail.substring(0, 3))*12f);
			}
		}else if(type.equals("家电清洗")){
			if(j_type.equals("冰箱")){
				String[] numbers=typeDetail.split(";")[1].split(",");
				Float count=0f;
				count+=Float.valueOf(numbers[0])*150f+Float.valueOf(numbers[1])*200f+Float.valueOf(numbers[2])*265f;
				param.put("price", count);
			}else if(j_type.equals("空调")){
				String[] numbers=typeDetail.split(";")[1].split(",");
				Float count=0f;
				count+=Float.valueOf(numbers[0])*120f+Float.valueOf(numbers[1])*150f;
				param.put("price", count);
			}else if(j_type.equals("洗衣机")){
				String[] numbers=typeDetail.split(";")[1].split(",");
				Float count=0f;
				count+=Float.valueOf(numbers[0])*180f+Float.valueOf(numbers[1])*180f;
				param.put("price", count);
			}else if(j_type.equals("油烟机")){
				String[] numbers=typeDetail.split(";")[1].split(",");
				Float count=0f;
				count+=Float.valueOf(numbers[0])*130f+Float.valueOf(numbers[1])*150f+Float.valueOf(numbers[2])*170f;
				param.put("price", count);
			}

		}else if(type.equals("地板护理")){
			param.put("price", Float.valueOf(typeDetail)*5f);
		}else if(type.equals("擦玻璃")){
			param.put("price", Float.valueOf(typeDetail)*10f);

		}
	/*	if(user.getMemberLevel().equals("VIP1")||user.getMemberLevel().equals("VIP2")){
			param.put("price", (Float)param.get("price")*0.75f);
		}else if(user.getMemberLevel().equals("VIP3")||user.getMemberLevel().equals("VIP4")){
			param.put("price", (Float)param.get("price")*0.7f);
		}else if(user.getMemberLevel().equals("VIP5")){
			param.put("price", (Float)param.get("price")*0.65f);
		}*/
		if(type.equals("开荒保洁")){
			param.put("service_Price", (Float)param.get("price")*0.05);
		}else{
			param.put("service_Price", (Float)param.get("price")*0.8);
		}
		String tDetail="";
		if(typeDetail.substring(0, 1).equals("单")||typeDetail.substring(0, 1).equals("欧")||typeDetail.substring(0, 1).equals("波")||typeDetail.substring(0, 1).equals("挂")){
			String[] types=typeDetail.split(";");
			String[] type1=types[0].split(",");
			String[] type2=types[1].split(",");
			if(typeDetail.substring(0, 1).equals("波")||typeDetail.substring(0, 1).equals("挂")){
				tDetail=type1[0]+"*"+type2[0]+","+type1[1]+"*"+type2[1];
			}else{
				tDetail=type1[0]+"*"+type2[0]+","+type1[1]+"*"+type2[1]+","+type1[2]+"*"+type2[2];
			}
			param.put("typeDetail", tDetail);
		}
		
		param.put("orderTime", changeDay(orderTime));
		SimpleDateFormat sss = new SimpleDateFormat("yyyyMMddHHmmss");
		String orderNumber=sss.format(new Date());
		param.put("orderNumber",getOrderNumber() );
		param.put("timeSlot", timeSlot);
		if(type.equals("家电清洗")){
			yuyueDao.createJDanci(param);
		}else if(type.equals("沙发护理")){
			yuyueDao.createSDanci(param);

		}else if(type.equals("擦玻璃")){
			yuyueDao.createCDanci(param);

		}else if(type.equals("开荒保洁")){
			yuyueDao.createKDanci(param);

		}else if(type.equals("地板护理")){
			yuyueDao.createDDanci(param);

		}
		map.put("orderNumber", orderNumber);
		

		return map;
	}
	/*public Map<String, Object> kdanci(String uuid, String orderTime,String timeSlot, String k_type, String phoneNumber) throws ParseException {
		Map<String,Object> map=new HashMap<String,Object>();
		Map<String,Object> param=new HashMap<String,Object>();
		Address ad=wodeDao.findAddressByUuid(uuid);
		param.put("phoneNumber", phoneNumber);
		param.put("address", ad.getAddress());
		param.put("detailAddress", ad.getDetailAddress());
		param.put("realPhoneNumber", ad.getRealPhoneNumber());
		SimpleDateFormat xxx = new SimpleDateFormat("yyyy年MM月dd日");
		SimpleDateFormat sss = new SimpleDateFormat("yyyyMMddHHmmss");
		Date date=xxx.parse(orderTime);
		param.put("orderTime", date);
		param.put("orderNumber", sss.format(new Date()));
		param.put("k_type", k_type);
		param.put("timeSlot", timeSlot);
		yuyueDao.createKDanci(param);
		map.put("0", "成功");
		return map;
	}
	public Map<String, Object> sdanci(String uuid, String s_type, String count, String orderTime, String timeSlot,
			String phoneNumber) throws ParseException {
		Map<String,Object> map=new HashMap<String,Object>();
		Map<String,Object> param=new HashMap<String,Object>();
		Address ad=wodeDao.findAddressByUuid(uuid);
		param.put("phoneNumber", phoneNumber);
		param.put("address", ad.getAddress());
		param.put("detailAddress", ad.getDetailAddress());
		param.put("realPhoneNumber", ad.getRealPhoneNumber());
		SimpleDateFormat xxx = new SimpleDateFormat("yyyy年MM月dd日");
		SimpleDateFormat sss = new SimpleDateFormat("yyyyMMddHHmmss");
		Date date=xxx.parse(orderTime);
		param.put("orderTime", date);
		param.put("orderNumber", sss.format(new Date()));
		param.put("s_type", s_type);
		param.put("count", count);
		param.put("timeSlot", timeSlot);
		yuyueDao.createKDanci(param);
		map.put("0", "成功");
		return map;
	}*/
	public  synchronized  Map<String, Object> rcircle(String uuid,String serviceTime, String phoneNumber,String suppilies,String strdays,String weekTimes,String weeks) throws Exception {
		String circle=Test.test9(strdays,weekTimes,weeks);
		Address ad=wodeDao.findAddressByUuid(uuid);
		Map<String,Object> param=new HashMap<String,Object>();
		Map<String,Object> map=new HashMap<String,Object>();
		String[] days = circle.split(";");
		System.err.println(days[0].toString());
		String[] day=days[0].split(",");
		param.put("address", ad.getAddress());
		param.put("detailAddress", ad.getDetailAddress());
		param.put("realPhoneNumber", ad.getRealPhoneNumber());
		param.put("serviceTime",serviceTime);
		param.put("circle", circle);
		param.put("location", ad.getLocation());
		param.put("phoneNumber", phoneNumber);
		SimpleDateFormat sss = new SimpleDateFormat("yyyyMMddHHmmss");
		String orderNumber=sss.format(new Date());
		param.put("orderNumber", orderNumber);
		map.put("orderNumber", orderNumber);
		param.put("cleaningSupplies_Price",0f);
		System.err.println("day:"+day.length);
		System.err.println("weeks:"+Float.valueOf(weeks));

		Float serviceTime1=Float.valueOf(serviceTime)/(day.length/Float.valueOf(weeks));
		System.err.println("serviceTime1:"+serviceTime1);
		if(suppilies.equals("1")){
			param.put("cleaningSupplies_Price", serviceTime1*5*Float.valueOf(day.length));
		}
		param.put("price",75f*Float.valueOf(day.length));
		System.err.println(serviceTime1);
		if(serviceTime1!=2f){
					param.put("price", 30f*serviceTime1*Float.valueOf(day.length));
				}
//		String vip=wodeDao.findUserByPhone(phoneNumber).getMemberLevel();
//		if(vip.equals("VIP1")||vip.equals("VIP2")){
//			param.put("price",(Float)param.get("price")*(0.75f));
//		}else if(vip.equals("VIP3")||vip.equals("VIP4")){
//			param.put("price",(Float)param.get("price")*(0.7f));
//		}else if(vip.equals("VIP5")||vip.equals("VIP6")){
//			param.put("price",(Float)param.get("price")*(0.65f));
//		}

		param.put("price",(Float)param.get("price")+(Float)param.get("cleaningSupplies_Price"));
		param.put("service_Price",(Float)param.get("price")*0.05);
		yuyueDao.rcircle(param);
		return map;
	}
	static Map<String,Object> timeNumber(String orderTime) throws ParseException{
		Map<String,Object> param=new HashMap<String,Object>();
		SimpleDateFormat xxx = new SimpleDateFormat("yyyy年MM月dd日");
		SimpleDateFormat sss = new SimpleDateFormat("yyyyMMddHHmmss");
		Date date=xxx.parse(orderTime);
		param.put("orderTime", date);
		param.put("orderNumber", sss.format(new Date()));
		
		return param;
	}
		
	
	
	/**
	    *支付宝支付
	    * @param orderId 订单编号
	    * @param actualPay 实际支付金额
	    * @return
	 * @throws UnsupportedEncodingException 
	    */
	 private String getOrderInfoByAliPay(String orderId,float actualPay) throws UnsupportedEncodingException {

	      //回调页面
	      String ali_call_back_url = "http://139.196.102.135/cleaning/yuyue/signyz";
	      String seller_id = "raweishi@qq.com";//商户编号
	      String[] parameters={
	            "service=\"mobile.securitypay.pay\"",//固定值（手机快捷支付）
	            "app_id=\"2088912289724891\"",//合作身份者ID（16位）

	            "_input_charset=\"utf-8\"",
	            "notify_url=\""+ali_call_back_url+"\"",//通知地址
	            "out_trade_no=\""+orderId+"\"",//商户内部订单号
	            "subject=\"测试\"",//测试
	            "payment_type=\"1\"",//固定值
	            "seller_id=\""+seller_id+"\"",//账户邮箱
	           "total_fee=\""+"0.01"+"\"",//支付金额（元）

	            "body=\"订单说明\"",//订单说明            

	            "it_b_pay=\"30m\""
	      };
	      String signOrderUrl = signAllString(parameters);
	      return signOrderUrl;
	   }

	 

	/**
	 * 支付宝签名
	 * @param array
	 * @return
	 * @throws UnsupportedEncodingException 
	 */
	private String signAllString(String [] array) throws UnsupportedEncodingException{
	   StringBuffer sb = new StringBuffer("");
	   for (int i = 0; i < array.length; i++) {
	      if(i==(array.length-1)){
	         sb.append(array[i]);
	      }else{
	         sb.append(array[i]+"&");
	      }
	   }
	   System.err.println("测试："+sb.toString());
	   String sign = "";
	   try {
	      sign = URLEncoder.encode(RSA.sign(sb.toString(), "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBANjVKl6p3PXKwxJbjUAl+xFvTTUiRjechQ5Ci8b089toOp8Q8zKWQl+RJY11zYp+wmwcZxfmrdKjx0fjEIDEbU9M/2ljdIo1FRPkofujYd9WQK18XDv0iyTmd7XKpnCLL73QTNfsJweArUd/utNglXnzBm1X6Y77wML0z2mfA7PBAgMBAAECgYBIveqC63VnN+iNZg1S8eryhGZgZukriuTQTd7alh6hAqx35JXR6LrHmMgCVvznc3MCFd04FXlG6w7VvQUyTbNlgwOXMz3k5SLSktxXCkTbQMIOYmW9lE+HJuxQS2JrTziP1evqmiGC/Zt9anwfKjFW+bYQSvVQEc2NTroFSXqvgQJBAPNS+7jiPYeFWzrHsq5vGCx+JxGoXAiJmBuaZPzurkW3hEIlzfSbjSL7ZdQAjEEMKbM4wqsoKvuMUB5VOGYtockCQQDkIOMMk3ZZxq7u19FSVSZv3QlJnA1DHKO/q196buhH5J21mr+n5m0UPYZoPueMJMR9CZvaH8lP2kogv8Z6TD45AkEAhDsBfty78UzgYhYqHS9UZMF9u9PRh/Y2SjHiVa3j2RE897GRti9eSLd0A/z0O1k/xBzBdcATc7Yxx/op9yUvOQJBAILY8iIGer2nnjLUivVkbbV/3JHh9iFmTe3kB9Gbx5Nk56iAaCmPm0UevPcSDZFujV0Co+gKj1dD53y9QsRm8tECQDvb1I9S4i4flckDl1p7tLT33ASFw3b+3fmZELUt+wtXYfHqeIje9OUCrGfkSql63PgcRglQ+YKVR1l0kjq5unI=", "utf-8"), "utf-8");//private_key私钥
	   } catch (UnsupportedEncodingException e) {
	      e.printStackTrace();
	   }
	   sb.append("&sign=\""+sign+"\"&");
	   sb.append("sign_type=\"RSA\"");
	   return sb.toString();
	}
	public Map<String, Object> sign() throws UnsupportedEncodingException {
		Map<String,Object> map=new HashMap<String,Object>();
		String sign=getOrderInfoByAliPay( "20170414140808", 10f);
		String str=RSA.sign("service=\"mobile.securitypay.pay\"&partner=\"2088912289724891\"&_input_charset=\"utf-8\"&notify_url=\"www.yiyunwangl.com\"&out_trade_no=\"20170414140808\"&subject=\"测试\"&payment_type=\"1\"&seller_id=\"raweishi@qq.com\"&total_fee=\"0.01\"&body=\"订单说明\"&it_b_pay=\"30m\"", "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBANjVKl6p3PXKwxJbjUAl+xFvTTUiRjechQ5Ci8b089toOp8Q8zKWQl+RJY11zYp+wmwcZxfmrdKjx0fjEIDEbU9M/2ljdIo1FRPkofujYd9WQK18XDv0iyTmd7XKpnCLL73QTNfsJweArUd/utNglXnzBm1X6Y77wML0z2mfA7PBAgMBAAECgYBIveqC63VnN+iNZg1S8eryhGZgZukriuTQTd7alh6hAqx35JXR6LrHmMgCVvznc3MCFd04FXlG6w7VvQUyTbNlgwOXMz3k5SLSktxXCkTbQMIOYmW9lE+HJuxQS2JrTziP1evqmiGC/Zt9anwfKjFW+bYQSvVQEc2NTroFSXqvgQJBAPNS+7jiPYeFWzrHsq5vGCx+JxGoXAiJmBuaZPzurkW3hEIlzfSbjSL7ZdQAjEEMKbM4wqsoKvuMUB5VOGYtockCQQDkIOMMk3ZZxq7u19FSVSZv3QlJnA1DHKO/q196buhH5J21mr+n5m0UPYZoPueMJMR9CZvaH8lP2kogv8Z6TD45AkEAhDsBfty78UzgYhYqHS9UZMF9u9PRh/Y2SjHiVa3j2RE897GRti9eSLd0A/z0O1k/xBzBdcATc7Yxx/op9yUvOQJBAILY8iIGer2nnjLUivVkbbV/3JHh9iFmTe3kB9Gbx5Nk56iAaCmPm0UevPcSDZFujV0Co+gKj1dD53y9QsRm8tECQDvb1I9S4i4flckDl1p7tLT33ASFw3b+3fmZELUt+wtXYfHqeIje9OUCrGfkSql63PgcRglQ+YKVR1l0kjq5unI=", "utf-8");
		System.err.println(sign);
		Boolean b=RSA.verify("service=\"mobile.securitypay.pay\"&partner=\"2088912289724891\"&_input_charset=\"utf-8\"&notify_url=\"www.yiyunwangl.com\"&out_trade_no=\"20170414140808\"&subject=\"测试\"&payment_type=\"1\"&seller_id=\"raweishi@qq.com\"&total_fee=\"0.01\"&body=\"订单说明\"&it_b_pay=\"30m\"", str, "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDY1Speqdz1ysMSW41AJfsRb001IkY3nIUOQovG9PPbaDqfEPMylkJfkSWNdc2KfsJsHGcX5q3So8dH4xCAxG1PTP9pY3SKNRUT5KH7o2HfVkCtfFw79Isk5ne1yqZwiy+90EzX7CcHgK1Hf7rTYJV58wZtV+mO+8DC9M9pnwOzwQIDAQAB",  "utf-8");
		map.put("0", sign);
		map.put("1", b);
		return map;
	}
	public String signyz() {
		return "success";
	}

	
	public Map<String, Object> newsign(String orderNumber ,String type,String redeemCode) {
		//实例化客户端
		Map<String,Object> map=new HashMap<String,Object>(); 
		AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do","2017041706761280", "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC6gPcD83dvy5w4JqudeYD1PiT0UdnMNQcoTiaLoIJPMwPwtngB7ov6iFdxRUoADVAjJfijGj8R3qlZX5/5KqQZM2VGMmN5Nt5G9zaX2D0m1MXewjJfRakgGF1Z5WMCs6YZp464YR9JgnmA+XzRroFu83EWHs59mGfjHMNcYhx27k6CaE3PkMk3IOjuFUw9AJDncGjRwxFQkC5HLjz78J5fETFbb6OtRiiWlC6QsvR8Kl7s3RMn/otSuyTfgQDIITDgNFV6skksrKJqUlj5p5JxHCGgkldCoSrME/0/QiKTO1hRtMflrxwnlQqtxyblwck34asjx1+9gatz3//HVxpnAgMBAAECggEAMzIPnJAKqy+TNH65AUNHOQrUDhUh2kJ8Mn4xaoam/qKcZElSbAVVe3JNvpQsmhMNeniD5hHgWkFq71OmkDk6ToijNj/CupVrMsPNwqTjNHOX1Wwtc6WlpV/K0FB9e1JhOA2cydQvSHh+bf8OWmiyswg0dMQEHsnlSpysrAFqmuKa1jqNYYhJuUx6VZOFgmPKVQCd3VIA9JTP3KL73n7uJIjJZI+1OtbW2I2/w22kYrWDCT0GdizaYqPWNRetpBB/81a8VAIJiRpmCKcPcPsudURvhEx6Fg9jzYfQqNU31ZhTRPY+Ad4f4gNsRq2INKMwgPo6Q2MwYReUW69/Q2QI0QKBgQD3tWAu9hKprlMbOs2mr4knn/c++BDxp47iHoQybnH7cABLAIIVvJamz8CItyBiydSP7afa3ZSwzGA5ScjhetePCH2IU1lRY5V2UisC4o/tidqD1JBuW7sVvYejDv0M00p9CSsuWoLnXqtx2PZQInEgcf+qqc+c271X0Q7grOVGXQKBgQDAvx+TyqQg0ivtQxAphimBWGTGCokUftSNOhHir/Lb6z02pp3XGoy0W/M0rNdqyVUhEMui+JmaGRfTzqt5uUrTyuz3SvI0VSw+v9NvIne0m2Wiy6M3jvbKVedO/pR6xai52koXVh7yf7j7lkNLInAXc9mWo2KiAZ1QxaA2mU1PkwKBgAqSXhmC/Qbq3rchylcb1MGxLQ8t7SMzIID8Bm5Ukl7Fx+1rhyHAW7mg0jnDfwlYTc8auHg5zrfA8TZgtMcSxBJhrWHdFMnJcz6KgTVtT/E2WfIYZ1Weapyh6yEFab1bYyl087fVuxJ+0thYByMiZSuaUewJtUefhTQzQuxJ1LstAoGBAJc+IWgVzT4XzPIq+maq6KyfEMw5fiD/+Ics9tXa3IVmjCzzBs2//oKT2D4QFiSsAMmmZTPnQJgjcof4FqO4GpggFlthirY30zUVzrHY6PdmLJVWlydEXjCcwZlBuH6x1NipChRPto7wW9XGrd0qE6zDcgx6/i1DeQ7lU/cjyf9TAoGBAIfEDIItVLQPLmofl8hmoGKmXLTXcU3s402737T+9C32ULAlwjKOPk+FnHMvV7Rn5l3ObZAuClpeYYSZB0KF+T6+FhjDMhjdQHpE1av/tK1p6SVBXdjHSTae01vKd76Hadqi7adqmYqiTZ5sCBeitoTO0deiuPUU1MvD6P9pn8oM","json","utf-8","MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgUzgScmclb96eh8AWc6TOOFK1dC2g2E4/S+q0WYQ3e633nkG7uxy0j1V+j/2PKLTn3XEMxWENBHkgrNmnmelYdzhonvt89pAo5Np3Fwma7lAtQOXdmAcQFwio6hU2kruPxJ0Zc+y/0uZzOC33QMNQP7tXUA+n8c/hCU9uoXzLGh5wl/84gKukwlK/BQ7FTNFb+KV/LnN2Z/Xvzux1E+rD8FhGhIHwSMCUaD4lkB0WCol/vFy3FNdnooo7xoFD+z0RhHID3lQIQdTfNbHQtSYw+t7F1J+nTDDq94nvWaG5d0u1Lqr9m2jCFihoOsKS3q9lcnmyU2QkC0bY1XfMf3AGQIDAQAB", "RSA2");
		//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称：alipay.trade.app.pay
		AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
		//SDK已经封装掉了公共参数，这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
		AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
		String price="";
		if(type.equals("日常保洁")){
			ROrder r=orderDao.findROrder(orderNumber);
			price=r.getRealPrice()+"";
		}else if(type.equals("沙发护理")){
			SOrder r=orderDao.findSOrder(orderNumber);
			price=r.getRealPrice()+"";
		}else if(type.equals("开荒保洁")){
			KOrder r=orderDao.findKOrder(orderNumber);
			price=r.getRealPrice()+"";
		}else if(type.equals("家电清洗")){
			JOrder r=orderDao.findJOrder(orderNumber);
			price=r.getRealPrice()+"";
		}else if(type.equals("地板护理")){
			DOrder r=orderDao.findDOrder(orderNumber);
			price=r.getRealPrice()+"";
		}else if(type.equals("擦玻璃")){
			COrder r=orderDao.findCOrder(orderNumber);
			price=r.getRealPrice()+"";
		}
		if(redeemCode!=null&&!redeemCode.equals("")){
			Coupon cp=yuyueDao.findCouponByRedeemCode(redeemCode);
			price=(Float.valueOf(price)-Float.valueOf(cp.getDiscountAmount()))+"";

		}
		model.setBody("我是云家洁,"+redeemCode+",1");
		model.setSubject(type);
		model.setOutTradeNo(orderNumber);
		model.setTimeoutExpress("30m");
		model.setTotalAmount(price);
		model.setProductCode("QUICK_MSECURITY_PAY");
		request.setBizModel(model);
		request.setNotifyUrl("http://139.196.102.135/cleaning/yuyue/yanzheng");
		try {
		        //这里和普通的接口调用不同，使用的是sdkExecute
		        AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
		        map.put("0", response.getBody());
		        return map;//就是orderString 可以直接给客户端请求，无需再做处理。
		    } catch (AlipayApiException e) {
		        e.printStackTrace();
		}		return null;
	}
	public String yanzheng() throws AlipayApiException, UnsupportedEncodingException, ParseException {
		//获取支付宝POST过来反馈信息
		HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();  
		Map<String,String> params = new HashMap<String,String>();
		Map<String, String[]> requestParams = request.getParameterMap();
		String orderNumber="";
		String type="";
		String redeemCode="";
		for (Iterator<String> iter = requestParams.keySet().iterator(); iter.hasNext();) {
		    String name = (String) iter.next();
		    String[] values = (String[]) requestParams.get(name);
		    String valueStr = "";
		    for (int i = 0; i < values.length; i++) {
		        valueStr = (i == values.length - 1) ? valueStr + values[i]
		                    : valueStr + values[i] + ",";
		       if(name.equals("out_trade_no")){
		    	   orderNumber=values[i];
		       }else if(name.equals("subject")){
		    	   type=values[i];
		       }else if(name.equals("body")){
		    	   redeemCode=values[i].split(",")[1];
		       }
		    }
		    
		  //乱码解决，这段代码在出现乱码时使用。
		  //valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8");
		    params.put(name, valueStr);	
		}
		//切记alipaypublickey是支付宝的公钥，请去open.alipay.com对应应用下查看。
		//boolean AlipaySignature.rsaCheckV1(Map<String, String> params, String publicKey, String charset, String sign_type)
		boolean flag = AlipaySignature.rsaCheckV1(params, "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgUzgScmclb96eh8AWc6TOOFK1dC2g2E4/S+q0WYQ3e633nkG7uxy0j1V+j/2PKLTn3XEMxWENBHkgrNmnmelYdzhonvt89pAo5Np3Fwma7lAtQOXdmAcQFwio6hU2kruPxJ0Zc+y/0uZzOC33QMNQP7tXUA+n8c/hCU9uoXzLGh5wl/84gKukwlK/BQ7FTNFb+KV/LnN2Z/Xvzux1E+rD8FhGhIHwSMCUaD4lkB0WCol/vFy3FNdnooo7xoFD+z0RhHID3lQIQdTfNbHQtSYw+t7F1J+nTDDq94nvWaG5d0u1Lqr9m2jCFihoOsKS3q9lcnmyU2QkC0bY1XfMf3AGQIDAQAB", "utf-8", "RSA2")	;
		Map<String,Object> param=new HashMap<String,Object>(); 
		param.put("orderNumber", orderNumber);
		param.put("redeemCode", redeemCode);
		param.put("payType", "支付宝");
		param.put("type", "订单付款");
		param.put("message", "类型:"+type+",订单编号:"+orderNumber);
		if(flag==true){
					if(type.equals("日常保洁")){
						if(!redeemCode.equals("")){
							Coupon cp=yuyueDao.findCouponByRedeemCode(redeemCode);
							param.put("discountAmount", cp.getDiscountAmount());

							yuyueDao.rbindCoupon(param);
							couponDao.deleteCoupon(redeemCode);
						}
						ROrder r=orderDao.findROrder(orderNumber);
						if(r.getOrderTime()==null||r.getOrderTime().equals("")){
							int start=0;
							int end=0;
							String circle=r.getCircle();
							String[] days=circle.split(";")[0].split(",");
							String[] slots=circle.split(";")[1].split(",");
							for(int i=0;i<days.length;i++){
								if(slots[i].substring(0, 1).equals("8")||slots[i].substring(0, 1).equals("9")){
									start=Integer.valueOf(slots[i].substring(0, 1));
								}else{
									start=Integer.valueOf(slots[i].substring(0, 2));
								}
								end=Integer.valueOf(slots[i].substring(slots[i].length()-5, slots[i].length()-3));
								updateYueMan(end-start+"",slots[i],days[i],1);
							}
						}else{
							updateYueMan(r.getServiceTime()+"", r.getTimeSlot(),new SimpleDateFormat("yyyy年MM月dd日").format(new SimpleDateFormat("yyyy-MM-dd").parse(r.getOrderTime())),1);
						}
						
						param.put("count", "+"+r.getRealPrice());
						controllDao.createTongji(param);
						yuyueDao.rzhifu(param);
					}else if(type.equals("沙发护理")){
						if(!redeemCode.equals("")){
							Coupon cp=yuyueDao.findCouponByRedeemCode(redeemCode);
							param.put("discountAmount", cp.getDiscountAmount());
							yuyueDao.sbindCoupon(param);
							couponDao.deleteCoupon(redeemCode);
						}
						SOrder r=orderDao.findSOrder(orderNumber);
						updateYueMan("4", r.getTimeSlot(),new SimpleDateFormat("yyyy年MM月dd日").format(new SimpleDateFormat("yyyy-MM-dd").parse(r.getOrderTime())),1);
						param.put("count", "+"+r.getRealPrice());
						controllDao.createTongji(param);
						yuyueDao.szhifu(param);
					}else if(type.equals("开荒保洁")){
						if(!redeemCode.equals("")){
							Coupon cp=yuyueDao.findCouponByRedeemCode(redeemCode);
							param.put("discountAmount", cp.getDiscountAmount());
							yuyueDao.kbindCoupon(param);
							couponDao.deleteCoupon(redeemCode);
						}
						KOrder r=orderDao.findKOrder(orderNumber);
						updateYueMan("4", r.getTimeSlot(),new SimpleDateFormat("yyyy年MM月dd日").format(new SimpleDateFormat("yyyy-MM-dd").parse(r.getOrderTime())),1);
						param.put("count", "+"+r.getRealPrice());
						controllDao.createTongji(param);
						yuyueDao.kzhifu(param);
					}else if(type.equals("家电清洗")){
						if(!redeemCode.equals("")){
							Coupon cp=yuyueDao.findCouponByRedeemCode(redeemCode);
							param.put("discountAmount", cp.getDiscountAmount());
							yuyueDao.jbindCoupon(param);
							couponDao.deleteCoupon(redeemCode);
						}
						JOrder r=orderDao.findJOrder(orderNumber);
						updateYueMan("4", r.getTimeSlot(),new SimpleDateFormat("yyyy年MM月dd日").format(new SimpleDateFormat("yyyy-MM-dd").parse(r.getOrderTime())),1);
						param.put("count", "+"+r.getRealPrice());
						controllDao.createTongji(param);
						yuyueDao.jzhifu(param);
					}else if(type.equals("地板护理")){
						if(!redeemCode.equals("")){
							Coupon cp=yuyueDao.findCouponByRedeemCode(redeemCode);
							param.put("discountAmount", cp.getDiscountAmount());
							yuyueDao.dbindCoupon(param);
							couponDao.deleteCoupon(redeemCode);
						}
						DOrder r=orderDao.findDOrder(orderNumber);
						updateYueMan("4", r.getTimeSlot(),new SimpleDateFormat("yyyy年MM月dd日").format(new SimpleDateFormat("yyyy-MM-dd").parse(r.getOrderTime())),1);
						param.put("count", "+"+r.getRealPrice());
						controllDao.createTongji(param);
						yuyueDao.dzhifu(param);
					}else if(type.equals("擦玻璃")){
						if(!redeemCode.equals("")){
							Coupon cp=yuyueDao.findCouponByRedeemCode(redeemCode);
							param.put("discountAmount", cp.getDiscountAmount());
							yuyueDao.cbindCoupon(param);
							couponDao.deleteCoupon(redeemCode);
						}
						COrder r=orderDao.findCOrder(orderNumber);
						updateYueMan("4", r.getTimeSlot(),new SimpleDateFormat("yyyy年MM月dd日").format(new SimpleDateFormat("yyyy-MM-dd").parse(r.getOrderTime())),1);
						param.put("count", "+"+r.getRealPrice());
						controllDao.createTongji(param);
						yuyueDao.czhifu(param);
					}
				}
		
		
		return "success";
	
	}
	public Map<String, Object> getParam() throws UnsupportedEncodingException {
		Map<String,Object> map=new HashMap<String,Object>();
		String privatekey="MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCP3jsVOOO1VLxMUowsgzopCtNLKKAxE4UMoXTQAW7LTbsIkf0YNV9WNl0S86SGp1FJpMWcDYR0GCd0P+j5OrVkImb+jeSxSJa9KBsExOD2sT3+vrxbvVpj5FnErx68v8JXSHKpRVWEctyAoi8vpnPl/dEZwJ12wQgU2QlR+fMsaT6ySw9qAVcb5buRkss2/hN2M729UJt38+XQ1Z8/6Mlf/owTzkKZazNS6jotbyFnNhwMJR/RzgtGvMbhFLmodt/UnB2zzlKFswIAkBB+f9POSjsmaP66hChLxSqWA3xXp4y3j2hCK+dUt4Egdph76no8qH6VL1ebY3lVyIl++5O7AgMBAAECggEAUhTZorcNe7R3phfmr7LDKQ1rFdN86eMYIuevLMnUe5vCnRYlz30MArULjzeA4+5sO1cOA4XWzyHEyNd5xVBQk2vpVUyBcQBYOF28ZJErRLRFCaWq87Bp9NoguU2sfMXvTDsiaB8Ntn6N/boKr+YI8+xHM6kobcueH77gSWwQ6IHbPMt4RSOmW8ctdMTsMH6swiz0YvdntklkEj8SlUD7W74V+4jtTWvobSLPSxF5ey+7WtvhLYFu/bD3kiD3LSGyAp03/bChL3SkDlR2WFeO6i/jD6UP2lSYGhdGVxdRySIunIpLHK9A+H7Lk4sbrpd1dTxdO+digRLcvDPEd013oQKBgQDU/50ZdNb49+rWbv0lBzY0xL/43dkLf+tPgZ0+av2mNToxH6K85mg6t9Eo7rsjTQlqGbRCZMwTS6vhP5e5wimmDeHzaLUrrulyIzVbD6krzkZraobUZit9MTeApLOVgE5bmU+AvrKnM9SkVCISoxygUtJ7nGgup9vQRTG5Tq/UcQKBgQCs6cFdDlPCOIJd0eUqXRXdP+Pic1x1gk5dar4QxAYvGH2QTEk0B/EcBdkVUAiJfmuqhzVVc0nlMyIBOMlyQBTiYnNonIbuMJ9SbjzjJhnqSI49kdu/KFAidIrFiePkIHoQYTkwtBowMr5eqxseow6+HlKvM8OFiodJAAtbl1SQ6wKBgCHcvWoVpDOSnngWzxH68ogzG14CTwZAAPXz4j7RHaA16Bl1MRcc/kcPgCYkxgWXsr52daz0f2k154544LM8hgiLPnfHFr5qIVzu8gWXGMsJETL0jZjo4VMW5v8BsDc9Xbe8SOJr7tUcLVsusPgLjHqEkEfslreMIisbRQtz0gpRAoGAQNS0ByvkA6IkXwDfp26XUAkwbCtMs1JUB3qKIMceenH4Qi4YFEYWBKe8qN0FFmgr/hgLyyoavrDZQxQDk66rJeY71zE49f2M/t8OPSx/8vOZQUR628VFpmWD0mTM6S+0FIgfZT9hwkiEUAJffLEuSeIcpkwGNv+lkZ1OpNysfFkCgYEArI6fZN880oMLv98q6xUJfVE4PJawBQ14NT0/aaz/on75xLJlFWM+ouTlSivWNmTwN8t6G0XfedKTuB21ZdVyClCT7Kw5UhlQeOY+P4kb8PQB+Mjj6GHDjMPglLvJo+lcPtGs5mBe82NXMgtsRwpj68ndbblHER3ACFKQi4oKFnU=";
		String publickey="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAj947FTjjtVS8TFKMLIM6KQrTSyigMROFDKF00AFuy027CJH9GDVfVjZdEvOkhqdRSaTFnA2EdBgndD/o+Tq1ZCJm/o3ksUiWvSgbBMTg9rE9/r68W71aY+RZxK8evL/CV0hyqUVVhHLcgKIvL6Zz5f3RGcCddsEIFNkJUfnzLGk+sksPagFXG+W7kZLLNv4TdjO9vVCbd/Pl0NWfP+jJX/6ME85CmWszUuo6LW8hZzYcDCUf0c4LRrzG4RS5qHbf1Jwds85ShbMCAJAQfn/Tzko7Jmj+uoQoS8UqlgN8V6eMt49oQivnVLeBIHaYe+p6PKh+lS9Xm2N5VciJfvuTuwIDAQAB";
		map.put("PARTNER", "2088912289724891");
		map.put("SELLER", "raweishi@qq.com");
		map.put("PRIVATE_KEY", new BASE64Encoder().encode(privatekey.getBytes("utf-8")));
		map.put("PUBLIC_KEY", new BASE64Encoder().encode(publickey.getBytes("utf-8")));

		return map;
	}
	/*1筛选上班中的阿姨
	 *2筛选阿姨的职能 
	 *3筛选阿姨的归属地
	 *4得到约满总数
	 *5比较约满总数和约满表 给用户显示约满时间表
	 *4预约成功 约满表各时间+1
	 */
	public int getAuntCount(String type,String uuid) throws UnsupportedEncodingException {
		int count=0;
		String ad =wodeDao.findAddressByUuid(uuid).getLocation();
		List<ServicePersonal> servicePersonals=yuyueDao.findWorkingAunt();
		for(ServicePersonal sp:servicePersonals){
			if(ad.equals(sp.getHoneLocation())){
				String[] serviceTypes=sp.getServiceType().split(",");
				for(int i = 0; i < serviceTypes.length; i++){
			        if(serviceTypes[i].equals(type)){
			        	count++;
			        }
			    }
			}
			
		}
		return count;
	}
	public int getOneYueMan(String day,int  i) throws UnsupportedEncodingException, ParseException {
		YueMan ym=yuyueDao.findYueMan(changeDay( day));
		if(i==8){
			return ym.getTime8();
		}else if(i==9){
			return ym.getTime9();
		}else if(i==10){
			return ym.getTime10();
		}else if(i==11){
			return ym.getTime11();
		}else if(i==12){
			return ym.getTime12();
		}else if(i==13){
			return ym.getTime13();
		}else if(i==14){
			return ym.getTime14();
		}else if(i==15){
			return ym.getTime15();
		}else if(i==16){
			return ym.getTime16();
		}else if(i==17){
			return ym.getTime17();
		}else if(i==18){
			return ym.getTime18();
		}else{
			return 0;
		}
		
	}
	public synchronized void updateYueMan(String serviceTime,String timeSlot,String  orderTime,int count) throws UnsupportedEncodingException, ParseException {
		Map<String,Object> param=new HashMap<String,Object>();
		param.put("orderTime",  changeDay(orderTime));
		param.put("count",  count);

		Integer a=Integer.valueOf(timeSlot.substring(0, 1));
		int intTime=Integer.valueOf(serviceTime.split("\\.")[0]);
		//如果是8  9点
		if(a!=1){
			for(int i=0;i<=intTime;i++){
				if(a==8){
					param.put("timeOne","time8");
				}else if(a==9){
					param.put("timeOne","time9");
				}else if(a==10){
					param.put("timeOne","time10");
				}else if(a==11){
					param.put("timeOne","time11");
				}else if(a==12){
					param.put("timeOne","time12");
				}else if(a==13){
					param.put("timeOne","time13");
				}else if(a==14){
					param.put("timeOne","time14");
				}
				yuyueDao.updateYueMan(param);
				a++;
			}
		}else{
			a=Integer.valueOf(timeSlot.substring(0, 2));
			for(int i=0;i<=intTime;i++){
				if(a==15){
					param.put("timeOne","time15");
				}else if(a==16){
					param.put("timeOne","time16");
				}else if(a==10){
					param.put("timeOne","time10");
				}else if(a==11){
					param.put("timeOne","time11");
				}else if(a==12){
					param.put("timeOne","time12");
				}else if(a==13){
					param.put("timeOne","time13");
				}else if(a==14){
					param.put("timeOne","time14");
				}
				yuyueDao.updateYueMan(param);
				a++;
			}
		}
	}
	public Map<String, Object> ylunbo() {
		String[] start={"133","153","180","181","189","130","131","132","145","155","156","185","186","134","135","136","137","138","139","147","150","151","152","157","158","159","182","183","184","187","188"};
		  String[] name={"林","赵","王","胡","余","陈","郑","薛","江"};
		List<String> list=new ArrayList<String>();
		
		 List<YOrder> ylist=orderDao.findYdaimianshi();
		 for(YOrder y:ylist){
			 list.add(y.getLinkMan().substring(0, 1)+"**("+y.getRealPhoneNumber().substring(0, 3)+"****"+y.getRealPhoneNumber().substring(y.getRealPhoneNumber().length()-5, y.getRealPhoneNumber().length())+")成功预约月嫂服务");
		 }
		 for(int i=0;i<20;i++){
				list.add(name[(int)(Math.random()*(name.length))]+"**("+start[(int)(Math.random()*(start.length))]+"****"+((int)(Math.random()*900)+100)+")成功预约月嫂服务");
			}
		 Map<String,Object> map=new HashMap<String,Object>();
		 map.put("A", list);
		 return map;
	}
	
	
	
	
	/**
     * 
     * @方法名称:alipayRefundRequest
     * @内容摘要: ＜支付宝退款请求＞
     * @param out_trade_no 订单支付时传入的商户订单号,不能和 trade_no同时为空。
     * @param trade_no 支付宝交易号，和商户订单号不能同时为空
     * @param refund_amount 需要退款的金额，该金额不能大于订单金额,单位为元，支持两位小数
     * @return 
     * String
	 * @throws AlipayApiException 
     * @exception 
     * @author:鹿伟伟
     * @创建日期:2016年4月12日-下午4:53:30
     */
    public  synchronized Map<String, Object>  alipayRefundRequest(String out_trade_no,String refund_amount) throws AlipayApiException{

    	AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do","2017041706761280","MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC6gPcD83dvy5w4JqudeYD1PiT0UdnMNQcoTiaLoIJPMwPwtngB7ov6iFdxRUoADVAjJfijGj8R3qlZX5/5KqQZM2VGMmN5Nt5G9zaX2D0m1MXewjJfRakgGF1Z5WMCs6YZp464YR9JgnmA+XzRroFu83EWHs59mGfjHMNcYhx27k6CaE3PkMk3IOjuFUw9AJDncGjRwxFQkC5HLjz78J5fETFbb6OtRiiWlC6QsvR8Kl7s3RMn/otSuyTfgQDIITDgNFV6skksrKJqUlj5p5JxHCGgkldCoSrME/0/QiKTO1hRtMflrxwnlQqtxyblwck34asjx1+9gatz3//HVxpnAgMBAAECggEAMzIPnJAKqy+TNH65AUNHOQrUDhUh2kJ8Mn4xaoam/qKcZElSbAVVe3JNvpQsmhMNeniD5hHgWkFq71OmkDk6ToijNj/CupVrMsPNwqTjNHOX1Wwtc6WlpV/K0FB9e1JhOA2cydQvSHh+bf8OWmiyswg0dMQEHsnlSpysrAFqmuKa1jqNYYhJuUx6VZOFgmPKVQCd3VIA9JTP3KL73n7uJIjJZI+1OtbW2I2/w22kYrWDCT0GdizaYqPWNRetpBB/81a8VAIJiRpmCKcPcPsudURvhEx6Fg9jzYfQqNU31ZhTRPY+Ad4f4gNsRq2INKMwgPo6Q2MwYReUW69/Q2QI0QKBgQD3tWAu9hKprlMbOs2mr4knn/c++BDxp47iHoQybnH7cABLAIIVvJamz8CItyBiydSP7afa3ZSwzGA5ScjhetePCH2IU1lRY5V2UisC4o/tidqD1JBuW7sVvYejDv0M00p9CSsuWoLnXqtx2PZQInEgcf+qqc+c271X0Q7grOVGXQKBgQDAvx+TyqQg0ivtQxAphimBWGTGCokUftSNOhHir/Lb6z02pp3XGoy0W/M0rNdqyVUhEMui+JmaGRfTzqt5uUrTyuz3SvI0VSw+v9NvIne0m2Wiy6M3jvbKVedO/pR6xai52koXVh7yf7j7lkNLInAXc9mWo2KiAZ1QxaA2mU1PkwKBgAqSXhmC/Qbq3rchylcb1MGxLQ8t7SMzIID8Bm5Ukl7Fx+1rhyHAW7mg0jnDfwlYTc8auHg5zrfA8TZgtMcSxBJhrWHdFMnJcz6KgTVtT/E2WfIYZ1Weapyh6yEFab1bYyl087fVuxJ+0thYByMiZSuaUewJtUefhTQzQuxJ1LstAoGBAJc+IWgVzT4XzPIq+maq6KyfEMw5fiD/+Ics9tXa3IVmjCzzBs2//oKT2D4QFiSsAMmmZTPnQJgjcof4FqO4GpggFlthirY30zUVzrHY6PdmLJVWlydEXjCcwZlBuH6x1NipChRPto7wW9XGrd0qE6zDcgx6/i1DeQ7lU/cjyf9TAoGBAIfEDIItVLQPLmofl8hmoGKmXLTXcU3s402737T+9C32ULAlwjKOPk+FnHMvV7Rn5l3ObZAuClpeYYSZB0KF+T6+FhjDMhjdQHpE1av/tK1p6SVBXdjHSTae01vKd76Hadqi7adqmYqiTZ5sCBeitoTO0deiuPUU1MvD6P9pn8oM","json","UTF-8","MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgUzgScmclb96eh8AWc6TOOFK1dC2g2E4/S+q0WYQ3e633nkG7uxy0j1V+j/2PKLTn3XEMxWENBHkgrNmnmelYdzhonvt89pAo5Np3Fwma7lAtQOXdmAcQFwio6hU2kruPxJ0Zc+y/0uZzOC33QMNQP7tXUA+n8c/hCU9uoXzLGh5wl/84gKukwlK/BQ7FTNFb+KV/LnN2Z/Xvzux1E+rD8FhGhIHwSMCUaD4lkB0WCol/vFy3FNdnooo7xoFD+z0RhHID3lQIQdTfNbHQtSYw+t7F1J+nTDDq94nvWaG5d0u1Lqr9m2jCFihoOsKS3q9lcnmyU2QkC0bY1XfMf3AGQIDAQAB","RSA2");
    	AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
    	request.setBizContent("{" +
    	"    \"out_trade_no\":\""+out_trade_no+"\"," +
    	"    \"refund_amount\":"+refund_amount+"," +
    	"    \"refund_reason\":\"正常退款\"," +
    	"    \"out_request_no\":\"HZ01RF001\"," +
    	"    \"operator_id\":\"OP001\"," +
    	"    \"store_id\":\"NJ_S_001\"," +
    	"    \"terminal_id\":\"NJ_T_001\"" +
    	"  }");
    	Map<String,Object> map=new HashMap<String,Object>();
		
    	AlipayTradeRefundResponse response = alipayClient.execute(request);
    	if(response.isSuccess()){
    		 map.put("A", "success");
    		 tuikuanTongji(out_trade_no);
    		 return map;
    	} else {
    		 map.put("A", "failed");
    		 return map;
    	}
    	
    }
   

    public Map<String, String> wxRefund(HttpServletRequest request,HttpServletResponse response,
                         String orderId,String total_fee ,String path) throws Exception{
        Map<String,String> result=new HashMap<String,String>(); 
        orderId=changgeWXorderNumber(orderId);
        /*PageData pd = new PageData();
        pd = this.getPageData();*/
        String refundid = UUID.randomUUID().toString();
        String nonce_str = PayCommonUtil.CreateNoncestr1();
        String appId="wx50a88bb93c045066";
        String shh="1464213402";
        String refund_fee=total_fee;
        /*-----  1.生成预支付订单需要的的package数据-----*/
        SortedMap<String, String> packageParams = new TreeMap<String, String>();
        packageParams.put("appid", appId);  
        packageParams.put("mch_id", shh);  
        packageParams.put("nonce_str", nonce_str);  
        packageParams.put("op_user_id", shh);  
        packageParams.put("out_trade_no", orderId);  
        packageParams.put("out_refund_no", refundid);  
        packageParams.put("total_fee",total_fee);  
        packageParams.put("refund_fee",refund_fee);  
        /*----2.根据package生成签名sign---- */
        RequestHandler reqHandler = new RequestHandler(request, response);
        reqHandler.init("wx50a88bb93c045066", "def3512409d71b787d13a86074913515", "PShYrhYPrScAu3ZSzK5KdfE6Eb6aLsYL");
        String sign = reqHandler.createSign(packageParams);

        /*----3.拼装需要提交到微信的数据xml---- */
        String xml="<xml>"
        +"<appid>"+appId+"</appid>"
        + "<mch_id>"+shh+"</mch_id>"
        + "<nonce_str>"+nonce_str+"</nonce_str>"
        + "<op_user_id>"+shh+"</op_user_id>"
        + "<out_trade_no>"+orderId+"</out_trade_no>"
        + "<out_refund_no>"+refundid+"</out_refund_no>"
        + "<refund_fee>"+refund_fee+"</refund_fee>"
        + "<total_fee>"+total_fee+"</total_fee>"
        + "<sign>"+sign+"</sign>"
        +"</xml>";
        
             /*----4.读取证书文件,这一段是直接从微信支付平台提供的demo中copy的，所以一般不需要修改---- */
             KeyStore keyStore  = KeyStore.getInstance("PKCS12");
             FileInputStream instream = new FileInputStream(new File(path));
             try {
                 keyStore.load(instream, shh.toCharArray());
             } finally {
                 instream.close();
             }
             // Trust own CA and all self-signed certs
             SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, shh.toCharArray()).build();
             // Allow TLSv1 protocol only
             SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext,new String[] { "TLSv1" },null,
                     SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
             CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(sslsf).build();

             /*----5.发送数据到微信的退款接口---- */
             String url="https://api.mch.weixin.qq.com/secapi/pay/refund";
             HttpPost httpost= HttpClientConnectionManager.getPostMethod(url);
             httpost.setEntity(new StringEntity(xml, "UTF-8"));
             HttpResponse weixinResponse = httpClient.execute(httpost);
             String jsonStr = EntityUtils.toString(weixinResponse.getEntity(), "UTF-8");
             System.err.println(jsonStr);
             Map map = GetWxOrderno.doXMLParse(jsonStr);
             if("success".equalsIgnoreCase((String) map.get("return_code"))){
                 System.err.println("退款成功");
                 result.put("returncode", "ok");
                 result.put("returninfo", "退款成功");
                 tuikuanTongji(orderId.substring(0, 14));
             }else{
                 System.err.println("退款失败111");
                 result.put("returncode", "error");
                 result.put("returninfo", "退款失败");
             }
      
        return result;

    }
   
    
   
	public  synchronized Map<String, String> wxtuikuan(HttpServletRequest request,HttpServletResponse response,String orderNumber,String total_fee) throws Exception{
        String filePath = "C:\\Users\\lxc2\\Desktop\\cerp\\apiclient_cert.p12"; //退款需要提供证书数据，所以需要根据证书路径读取证书
        //需要退款的商户订单号，对应提交订单中的out_trade_no
        Map<String,String> result = (Map<String, String>) wxRefund(request,response,orderNumber,total_fee,filePath);

        return result;
    }
    //获取不重复的订单号
    public  synchronized  String getOrderNumber() throws ParseException  {
		SimpleDateFormat sp=new SimpleDateFormat("yyyyMMddHHmmss");
		Date date=new Date();
		 Calendar calendar = Calendar.getInstance ();
			String  orderNumber=orderDao.findOrderNew();
			if(orderNumber==null){
				return sp.format(date);
			}else if(date.getTime()>sp.parse(orderNumber).getTime()+1000){
				return sp.format(date);
			}else{
				 calendar.setTime(sp.parse(orderNumber));  
				 calendar.add (Calendar.SECOND, 1);
				return (Long.valueOf(sp.format(calendar.getTime ())))+"";
			}
			
		
	}
    public  void tuikuanTongji(String orderId)    {
    	 Order or= orderDao.findTuikuanOrder(orderId);
         if(or.getOrderState().equals("待接单")){
        	 Map<String,Object> param=new HashMap<String,Object>(); 
      		param.put("type", "订单付款");
      		param.put("count", "+"+or.getRealPrice());
      		param.put("message", "类型:"+or.getType()+",订单编号:"+orderId);
         	controllDao.createTongji(param);
         }
  		
  	}
    private String changgeWXorderNumber(String orderId) {
		String wxorderNumber= yuyueDao.findWXorderByorderId(orderId);
		return wxorderNumber.substring(2, wxorderNumber.length());
	}
}	
	
	
	
	
	

	
	 
	
	
	

